#Boa:Dialog:Dialog1

import wx

def create(parent, app ):
    return Dialog1(parent, app )

[wxID_DIALOG1, wxID_DIALOG1BUTTONCREATEGAME, wxID_DIALOG1BUTTONREFRESH, 
 wxID_DIALOG1BUTTONSELECTGAME, wxID_DIALOG1LISTBOXAVAILABLEGAMES, 
 wxID_DIALOG1STATICBOX1, wxID_DIALOG1STATICBOX2, wxID_DIALOG1STATICTEXT1, 
 wxID_DIALOG1STATICTEXT2, wxID_DIALOG1TEXTCTRLGAMENAME, 
 wxID_DIALOG1TEXTCTRLMINPLAYERS, 
] = [wx.NewId() for _init_ctrls in range(11)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(472, 207), size=wx.Size(358, 422),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'Select game')
        self.SetClientSize(wx.Size(350, 395))
        self.Center(wx.BOTH)
        self.SetThemeEnabled(True)
        self.SetHelpText(u'sex')
        self.Bind(wx.EVT_CLOSE, self.OnDialog1Close)

        self.listBoxAvailableGames = wx.ListBox(choices=[],
              id=wxID_DIALOG1LISTBOXAVAILABLEGAMES,
              name=u'listBoxAvailableGames', parent=self, pos=wx.Point(16, 28),
              size=wx.Size(320, 236), style=0)

        self.buttonSelectGame = wx.Button(id=wxID_DIALOG1BUTTONSELECTGAME,
              label=u'Select game >>', name=u'buttonSelectGame', parent=self,
              pos=wx.Point(237, 271), size=wx.Size(100, 25), style=0)
        self.buttonSelectGame.Bind(wx.EVT_BUTTON, self.OnButtonSelectGame,
              id=wxID_DIALOG1BUTTONSELECTGAME)

        self.staticBox2 = wx.StaticBox(id=wxID_DIALOG1STATICBOX2,
              label=u'Create game', name='staticBox2', parent=self,
              pos=wx.Point(8, 304), size=wx.Size(336, 86), style=0)

        self.staticBox1 = wx.StaticBox(id=wxID_DIALOG1STATICBOX1,
              label=u'Select game', name='staticBox1', parent=self,
              pos=wx.Point(8, 8), size=wx.Size(336, 296), style=0)

        self.staticText1 = wx.StaticText(id=wxID_DIALOG1STATICTEXT1,
              label=u'New game name:', name='staticText1', parent=self,
              pos=wx.Point(16, 328), size=wx.Size(83, 13), style=0)

        self.textCtrlGameName = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRLGAMENAME,
              name=u'textCtrlGameName', parent=self, pos=wx.Point(104, 328),
              size=wx.Size(232, 21), style=0, value=u'')

        self.buttonCreateGame = wx.Button(id=wxID_DIALOG1BUTTONCREATEGAME,
              label=u'Create game!', name=u'buttonCreateGame', parent=self,
              pos=wx.Point(237, 356), size=wx.Size(100, 25), style=0)
        self.buttonCreateGame.Bind(wx.EVT_BUTTON, self.OnButtonCreateGameButton,
              id=wxID_DIALOG1BUTTONCREATEGAME)

        self.buttonRefresh = wx.Button(id=wxID_DIALOG1BUTTONREFRESH,
              label=u'Refresh', name=u'buttonRefresh', parent=self,
              pos=wx.Point(18, 271), size=wx.Size(100, 25), style=0)
        self.buttonRefresh.Bind(wx.EVT_BUTTON, self.OnButtonRefreshButton,
              id=wxID_DIALOG1BUTTONREFRESH)

        self.staticText2 = wx.StaticText(id=wxID_DIALOG1STATICTEXT2,
              label=u'Min players', name='staticText2', parent=self,
              pos=wx.Point(18, 360), size=wx.Size(54, 13), style=0)

        self.textCtrlMinPlayers = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRLMINPLAYERS,
              name=u'textCtrlMinPlayers', parent=self, pos=wx.Point(104, 360),
              size=wx.Size(100, 21), style=0, value=u'2')

    def __init__(self, parent, app ):
        self._init_ctrls(parent)
        self.app = app
        self.OnButtonRefreshButton( None )
        

    def OnButtonSelectGame(self, event):
        self.app.game_name = self.listBoxAvailableGames.GetStringSelection()
        
        if( self.app.game_name != '' ):
            self.EndModal(1)

    def OnButtonCreateGameButton(self, event):
        game_name = self.textCtrlGameName.GetValue()
        min_players = self.textCtrlMinPlayers.GetValue()
        self.app.server_proxy.create_game( game_name , int(min_players) )
        self.OnButtonRefreshButton( None )

    def OnDialog1Close(self, event):
        self.EndModal(0)

    def OnButtonRefreshButton(self, event):
        self.listBoxAvailableGames.Set( self.app.server_proxy.enum_games() )
